package com.uto.backend;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;

public class LocationService extends Service {

	private LocationManager locationManager;
	
	private HttpConnnectionThread httpThread;

	@Override
	public void onCreate(){
		super.onCreate();
		
		/*
		locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 
				0, new LocationUpdateHandler());
		*/
		

	}
	
	@Override
	public void onStart(Intent intent, int startId) {
		int lat = intent.getIntExtra("lat", -1);
		int lng = intent.getIntExtra("lng", -1);
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	// this inner class is the intent reciever that recives notifcations
	// from the location provider about position updates.
	public class LocationUpdateHandler implements LocationListener {

		public void onLocationChanged(Location loc) {
			int lat = (int) (loc.getLatitude()*1E6);
			int lng = (int) (loc.getLongitude()*1E6);
			
			
			ArrayList<NameValuePair> location = new ArrayList<NameValuePair>(2);
			location.add(new BasicNameValuePair("lat" , ""+lat));
			location.add(new BasicNameValuePair("lng" , ""+lng));
			
			
			/*
			int[] location = new int[2];
			location[0] = lat;
			location[1] = lng;
			Intent intent = new Intent(getBaseContext() , com.uto.backend.HttpConnnectionService.class);
			intent.putExtra(com.uto.backend.HttpConnnectionService.DATA, location);
			startService(intent);
			*/
		}

		public void onProviderDisabled(String provider) {}

		public void onProviderEnabled(String provider) {}

		public void onStatusChanged(String provider, int status, Bundle extras) {}

	}
}
